class CoolBtn extends egret.Bitmap
{
	public constructor(texture:egret.Texture,callback:Function,callbackObj:egret.DisplayObjectContainer) 
	{
		super();
		this.init(texture,callback,callbackObj);
	}
	private m_texture:egret.Texture;
	private m_disableTexture:egret.Texture;
	private m_Callback:Function;
	private m_CallbackObj:egret.DisplayObjectContainer;
	private m_touchBegin:boolean = false;
	private m_touchEnable:boolean = true;
	public init(texture:egret.Texture,callback:Function,callbackObj:egret.DisplayObjectContainer)
	{
		this.m_texture = texture;
		this.m_CallbackObj = callbackObj;
		this.m_Callback = callback;
		this.texture = texture;
		this.anchorOffsetX = this.width / 2;
		this.anchorOffsetY = this.height / 2;
		this.touchEnabled = true;
		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
		this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMoved, this);
		this.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
		this.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchCancel, this);
		this.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchCancel, this);
		
	}
	private touchBegin(event:egret.TouchEvent)
	{
		if(!this.m_touchEnable)
		{
			return;
		}
		this.m_touchBegin = true;
		this.scaleX = 1.1;
		this.scaleY = 1.1;
	}
	private touchMoved(event:egret.TouchEvent)
	{
		if(!this.m_touchEnable)
		{
			return;
		}
		//console.log("moved");
	}
	private touchEnd(event:egret.TouchEvent)
	{
		if(!this.m_touchEnable)
		{
			return;
		}
		if(this.m_Callback != null && this.m_touchBegin)
		{
			this.m_touchBegin = false;
			let bindFunction = this.m_Callback.bind(this.m_CallbackObj);
			bindFunction(event);
		}
		this.scaleX = 1.0;
		this.scaleY = 1.0;
	}
	public setDisableTexture(disableTexture:egret.Texture)
	{
		this.m_disableTexture = disableTexture;
	}
	public setEnabled(value:boolean)
	{
		this.m_touchEnable = value;
		if(value)
		{
			this.texture = this.m_texture;
		}
		else
		{
			this.texture = this.m_disableTexture;
		}
	}
	private touchCancel(event:egret.TouchEvent)
	{
		this.m_touchBegin = false;
		this.scaleX = 1.0;
		this.scaleY = 1.0;
	}
}